package com.controller;

import com.model._do.AppointmentDO;
import com.model._do.CollectResultDO;
import com.model._do.EquipmentDO;
import com.model._do.MedicalResultsDO;
import com.model.dto.baseDTO.ResultDTO;
import com.service.AppointmentService;
import com.service.CollectResultService;
import com.service.MedicalResultService;
import com.service.ResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/record")
public class RecordController {

    @Autowired
    public CollectResultService collectResultService;

    @Autowired
    public ResultService resultService;

    @Autowired
    public AppointmentService appointmentService;

    @Autowired
    public MedicalResultService medicalResultService;

    @RequestMapping(value = "/getEquipCollectRecord", method = RequestMethod.POST)
    public ResultDTO getEquipCollectRecord(@RequestBody EquipmentDO equipment){
        return resultService.createSuccess("success", collectResultService.getCollectByEquipId(equipment.getEquipId()));
    }

    @RequestMapping(value = "/getEquipAppointRecord", method = RequestMethod.POST)
    public ResultDTO getEquipAppointRecord(@RequestBody EquipmentDO equipment){
        return resultService.createSuccess("success", appointmentService.getAppointPast(equipment.getEquipId()));
    }

    /**
     * 返回一个equipId 的所有 医生-诊疗结果
     * @param equipment equipId
     * @return doctor,medicalResult
     */
    @RequestMapping(value = "/getEquipResultRecord", method = RequestMethod.POST)
    public ResultDTO getEquipResultRecord(@RequestBody EquipmentDO equipment){
        return resultService.createSuccess("success", medicalResultService.getByEquipment(equipment));
    }

    @RequestMapping(value = "/pushEquipCollectRecord", method = RequestMethod.POST)
    public ResultDTO pushEquipRecord(@RequestBody CollectResultDO collect){
        collectResultService.saveNewCollect(collect);
        return resultService.createSuccess();
    }

    @RequestMapping("/pushMedicalRecord")
    public ResultDTO pushMedicalRecord(@RequestBody MedicalResultsDO medical){
        try{
            medicalResultService.saveMedicalResult(medical);
            return resultService.createSuccess();
        } catch (Exception e){
            return resultService.createFailed();
        }
    }

    @RequestMapping("/getMedicalByAppoint")
    public ResultDTO getMedicalByAppoint(@RequestBody AppointmentDO appoint){
        try{
            return resultService.createSuccess("success",medicalResultService.getByAppoint(appoint));
        } catch (Exception e){
            return resultService.createFailed();
        }
    }
}
